package com.guigu.service.impl.stock;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.mapper.stock.SGatherDetailsMapper;
import com.guigu.pojo.stock.SGatherDetails;
import com.guigu.pojo.stock.SPayDetails;
import com.guigu.service.stock.SGatherDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr.Zhang
 * @since 2024-12-06
 */
@Service
public class SGatherDetailsServiceImpl extends ServiceImpl<SGatherDetailsMapper, SGatherDetails> implements SGatherDetailsService {

    @Autowired
    private SGatherDetailsMapper sGatherDetailsMapper;

    @Override
    public ArrayList<SGatherDetails> selectArrByParentId(Integer parentId) {
        QueryWrapper<SGatherDetails> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("PARENT_ID", parentId);
        ArrayList<SGatherDetails> sGatherDetails = (ArrayList<SGatherDetails>)sGatherDetailsMapper.selectList(queryWrapper);
        return sGatherDetails;

    }

    @Override
    public SGatherDetails selectById(Integer id) {
        SGatherDetails sGatherDetails = sGatherDetailsMapper.selectById(id);
        return sGatherDetails;
    }

    @Override
    public boolean updateSGatherDetails(SGatherDetails sGatherDetails) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("PARENT_ID",sGatherDetails.getParentId());
        queryWrapper.eq("PRODUCT_ID",sGatherDetails.getProductId());
        int rows = sGatherDetailsMapper.update(sGatherDetails, queryWrapper);
        return rows>0;
    }

    @Override
    public boolean selectParentId(Integer parentId, String gatherTag) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("PARENT_ID",parentId);
        queryWrapper.eq("GATHER_TAG",gatherTag);
        ArrayList<SGatherDetails> list = (ArrayList<SGatherDetails>)sGatherDetailsMapper.selectList(queryWrapper);
        if(list.size()>0){
            return true;
        }else{
            return false;
        }
    }
}
